package logic

import (
	"context"
	"github.com/google/uuid"
	"week3/projectsrv/models"
	"week3/projectsrv/service"

	"week3/projectsrv/internal/svc"
	"week3/projectsrv/projectsrv"

	"github.com/zeromicro/go-zero/core/logx"
)

type GenerateOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGenerateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GenerateOrderLogic {
	return &GenerateOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 生成订单
func (l *GenerateOrderLogic) GenerateOrder(in *projectsrv.GenerateOrderReq) (*projectsrv.GenerateOrderRes, error) {
	// todo: add your logic here and delete this line
	res, err := service.CreateOrder(&models.Order{
		OrderSn:    uuid.NewString(),
		TotalPrice: float64(in.TotalPrice),
		Status:     0,
	})
	if err != nil {
		return nil, err
	}
	return &projectsrv.GenerateOrderRes{
		OrderSn: res.OrderSn,
	}, nil
}
